package cn.cvs.servlet.sysRole;

import cn.cvs.pojo.SysRole;
import cn.cvs.service.SysRoleService;
import cn.cvs.util.Page;
import cn.cvs.util.SpringUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "ListRoleIndexServlet", urlPatterns = "/sys/role/list")
public class ListRoleIndexServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet ( request, response );
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding ( "utf-8" );
        response.setContentType ( "text/html;charset=UTF-8" );
        SysRoleService sysRoleService= (SysRoleService) SpringUtil.getBean ( "sysRoleService" );
        Page<SysRole> page = new Page();
        page.setPageSize ( 2 );
        page.setTotalCount ( sysRoleService.getCount () );
        page.setPageNo ( request.getParameter ( "pageNo" )!=null?Integer.parseInt ( request.getParameter ( "pageNo" ) ):1 );
        page.setList ( sysRoleService.getSysRoleAllListPage ( page.getPageNo (),page.getPageSize () ) );
        request.setAttribute ( "page",page );
        request.getRequestDispatcher ( "/WEB-INF/jsp/sysRole/list.jsp" ).forward ( request,response );
    }
}
